﻿<%@ control language="C#" autoeventwireup="true" inherits="UserControl_ManagerAdvertising, App_Web_pmcgjoc4" %>
<%@ Import Namespace="DacSanMienTayOBJ" %>

<%@ Import Namespace="System.Collections.Generic" %>
<script type="text/javascript" src="Scripts/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="<%=Utility.modHost %>/Scripts/jquery.simplemodal.js"></script>

<style>
#simplemodal-overlay {background-color:#000;}
#simplemodal-container {height:378px; width:619px; color:#bbb; background:url(../Images/bg_login.png) no-repeat center; padding:12px; position:relative;}
#simplemodal-container .simplemodal-data {position:relative;}
#simplemodal-container a.modalCloseImg {background:url(../Images/x.png) no-repeat; width:25px; height:29px; display:inline; z-index:3200; position:absolute; top:0px; right:0px; cursor:pointer;}

#simplemodal_container_uploadimage {height:490px; width:700px; color:#bbb;background-color:White;border:5px;border-style:solid;border-color:#ce5c00; position:relative;margin-top:50px}
#simplemodal_container_uploadimage .simplemodal-data {position:relative;}
#simplemodal_container_uploadimage a.modalCloseImg {background:url(../Images/x.png) no-repeat; width:25px; height:29px; display:inline; z-index:3200; position:absolute; top:-16px; right:-16px; cursor:pointer;}

</style>

<div>
<table>
<tr>
<td style="width:200px">
Tên quảng cáo
</td>
<td style="width:300px">
<input type="text" id="txtAdvName" name="txtAdvName" onfocus="ResetField(1)" />
<label id="lbErrorAdvName" style="color:Red"></label>
</td>
</tr>

<tr>
<td style="width:200px">
Vị trí quảng cáo
</td>
<td style="width:300px">
<select id="cbPosition" name="cbPosition" onclick="ResetField(2)">
<option value="0">Chọn vị trí quảng cáo</option>
<%
    try
    {
        List<AdvPosition> listPosition = AdvPositionBusiness.ListAllAdvPositionVisible(ConnectionType.AdminConnection);
        foreach (AdvPosition advPosition in listPosition)
        {
            
            %>
            <option value="<%=advPosition.AdvPositionID %>"><%=advPosition.AdvPoName %></option>
            <%
        }
    }
    catch
    {

    }
    
     %>
</select>
<label id="lbErrorPosition" style="color:Red"></label>
</td>
</tr>

<tr>
<td style="width:200px">
Link website
</td>
<td style="width:300px">
<input type="text" id="txtLink" name="txtLink" />
</td>
</tr>

<tr>
<td style="width:200px">
Logo
</td>
<td style="width:300px">
<asp:FileUpload ID="fileLogo" runat="server" />
<label id="lbErrorLogo" style="color:Red"></label>
<img id="imgLogo" width="100px" height="100px" />
</td>
</tr>


<tr>
<td style="width:200px">
Ghi chú
</td>
<td style="width:300px">
<textarea id="txtNote" name="txtNote" cols="1" rows="2" style="width:300px"></textarea>
</td>
</tr>

<tr>
<td style="width:200px">
<asp:Button ID="cmdAdd" Text="Thêm mới" runat="server" 
        OnClientClick=" return CheckValidate()" onclick="cmdAdd_Click" />
</td>
<td>
<asp:Button ID="cmdUpdate" Text="Cập nhật" runat="server" 
        OnClientClick=" return CheckValidateUpdate()" onclick="cmdUpdate_Click" />
</td>
</tr>
</table>
<input type="hidden" id="hdAdvID" name="hdAdvID" />
<input type="hidden" id="hdLogo" name="hdLogo" />
</div>


<div>
<span> Danh sách quảng cáo</span>

<table>
<tr>
<td style="width:200px">
Tên quảng cáo
</td>
<td style="width:120px">
Logo
</td>
<td style="width:150px">
Link website
</td>
<td style="width:150px">
Vị trí
</td>
<td style="width:100px">
Tình trạng
</td>
<td style="width:100px">
Chỉnh sữa
</td>

<td style="width:150px">
Khóa/mở khóa
</td>
</tr>

<tbody id="bodyAdvertising">
<%
    try
    {
        List<Advertising> list = AdvertisingBusiness.GetListAdvertisingAllAdmin(ConnectionType.AdminConnection);
        int vt = 0;
        foreach (Advertising adv in list)
        {
            string advName = adv.AdvName;
            string advPositionName = adv.AdvPositionName;
            string logo = Utility.modHost + "/" + adv.Logo;
            string status = "";
            if (adv.IsVisible == 1)
            {
                status = "Active";
            }
            else
            {
                status = "Inactive";
            }
            string link = adv.Link;
          
          
            %>
            <tr id="trAdvertising<%=vt %>">
            <td><%=advName %> </td>
            <td><img src="<%=logo %>" width="100px" height="100px" /></td>
            <td><%=link%></td>
            <td><%=advPositionName %></td>
            <td><%=status %></td>

            <td>
 
       <span style="color:Blue; cursor:pointer" title="<%=advName %>" id="<%=link %>"  onclick="ShowInfoAdvertising('<%=adv.AdvertisingID %>','<%=adv.AdvPositionID %>','<%=logo %>',this.title,this.id,'<%=adv.Note %>')"> Chỉnh sữa</span>
       </td>
       <td>
        <%
            if (adv.IsVisible == 1)
            {
                 %>
                    <input type="button" title="<%=adv.AdvertisingID %>"  value="Khóa" onclick="LockAndUnlockAdvertising(this.title,'lock','<%=vt %>','<%=advPositionName %>')" />
                <%
            }
            else
            {
             %>
                 <input type="button" title="<%=adv.AdvertisingID %>"  value="Mở khóa" onclick="LockAndUnlockAdvertising(this.title,'unlock','<%=vt %>','<%=advPositionName %>')" />
                <%
            }
                     %>

                     
       </td>

            </tr>
            <%
            
                vt++;
        }
    }
    catch
    {

    }
    
     %>
</tbody>

</table>
</div>

<script type="text/javascript">

    function CheckValidate() {
        var advName = $('#txtAdvName').val();
        var logo = $('#<%=fileLogo.ClientID %>').val();
        var advPosition = $('#cbPosition').val();
        var checkReg = true;
        if (advName == '') {
            checkReg = false;
            $('#lbErrorAdvName').text('*');
        }
        if (advPosition == '0') {
            checkReg = false;
            $('#lbErrorPosition').text('*');
        }
        if (logo == '') {
            checkReg = false;
            $('#lbErrorLogo').text('*');
        }

        if (!checkReg) {
            alert('Vui lòng kiểm tra lại dữ liệu');
            return false;
        }
        else {
            return true;
        }
    }

    function CheckValidateUpdate() {
        var advName = $('#txtAdvName').val();
        var advPosition = $('#cbPosition').val();
        var checkReg = true;
        if (advName == '') {
            checkReg = false;
            $('#lbErrorAdvName').text('*');
        }
        if (advPosition == '0') {
            checkReg = false;
            $('#lbErrorPosition').text('*');
        }
        if (!checkReg) {
            alert('Vui lòng kiểm tra lại dữ liệu');
            return false;
        }
        else {
            return true;
        }
    }

    function ResetField(id) {
        switch (id) {

            case 1:
                {
                    $('#lbErrorAdvName').text('');
                    break;
                }
            case 2:
                {
                    $('#lbErrorPosition').text('');
                    break;
                }
        }
    }

    function ShowInfoAdvertising(advID, advPoID, logo, advName, link, note) {

        $('#hdAdvID').val(advID);
        $('#txtAdvName').val(advName);
        $('#cbPosition option[value=' + advPoID + ']').attr("selected", true);
        $('#imgLogo').attr("src", logo);
        $('#txtLink').val(link);
        $('#txtNote').val(note);

        $('body,html').animate({ scrollTop: 0 }, 300);

    }

    function loadding() {
        var load = '<img src="<%=Utility.modHost %>/Images/loading.gif" id="imgLoad" alt="" style="margin-left:auto;margin-right:auto;margin-top:53%;margin-left:135%;width:40px;height:40px" />';
        $('#bodyAdvertising').html(load);
    }
    function LockAndUnlockAdvertising(advID, type, vt,advPoName) {
        var trID = '#trAdvertising' + vt;
        var load = '<img src="<%=Utility.modHost %>/Images/loading.gif" id="imgLoad" alt="" style="margin-left:auto;margin-right:auto;margin-top:53%;margin-left:135%;width:40px;height:40px" />';
        $(trID).html(load);
        $.post("<%=Utility.modHost %>/Proccess/ProccessLockAndUnlockAdvertising.aspx", { advID: advID, type: type, vt: vt, advPoName: advPoName }, function (data) {
            $('#imgLoad').attr("src", "");
            if (data == "lockfaile") {
                alert('Không khóa được quảng cáo này. Vui lòng liên hệ admin');
            }
            else if (data == "unlockfaile") {
                alert('Không mở khóa được quảng cáo này. Vui lòng liên hệ admin');
            }
            else {
                document.getElementById('trAdvertising' + vt).innerHTML = data;
            }
        });
    }
</script>